package com.sand.controller;

import com.sand.dto.Owner.DetailAdd;
import com.sand.dto.Owner.DetailAddScheme;
import com.sand.dto.Owner.DetailDelete;
import com.sand.dto.Owner.DetailDto;
import com.sand.entity.buy.detail;
import com.sand.result.ResponseResult;
import com.sand.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/detail")
public class DetailController {

    @Autowired
    private DetailService detailService;


    /**
     * 客户预购和修改
     */
    @PostMapping("/addOrupdate")
    private ResponseResult<String> addOrupdate(@RequestBody DetailAdd signAdd){

        String i  =  detailService.addOrupdate(signAdd);

        return new ResponseResult<String>().hint(i);
    }

    /**
     * 确认预购
     */
    @PostMapping("/addScheme")
    private ResponseResult<String> addScheme(@RequestBody Integer detailId){
        String str =  detailService.addScheme(detailId);
        return new ResponseResult<String>().hint(str);
    }



    /**
     * 客户删除预购
     */
    @PostMapping("/delete")
    private ResponseResult<Integer> delete(@RequestBody DetailDelete delete){

        Integer i = detailService.delete(delete);

        return new ResponseResult<Integer>().ok(i);
    }


    /**
     * 客户根据标记查询预购
     */
    @PostMapping("/select")
    private ResponseResult<DetailDto> select(@RequestBody String sign){
        DetailDto detailDto = detailService.select(sign);
        return new ResponseResult<DetailDto>().ok(detailDto);
    }

    /**
     * 根据id查询预购
     */
    @PostMapping("/getByid")
    private ResponseResult<detail> getByid(@RequestBody Integer id){
        return new ResponseResult<detail>().ok(detailService.getById(id));
    }


    /**
     * 查看客户对应的所有预购
     */
    @PostMapping("/selectAll")
    private ResponseResult<List<DetailDto>> selectAll(@RequestBody Integer userid){

        List<DetailDto> list = detailService.selectAll(userid);

        return new ResponseResult<List<DetailDto>>().ok(list);
    }



}
